<?php
/**
 * Created by PhpStorm.
 * User: worry
 * Date: 2018/2/8
 * Time: 17:00
 */

namespace backend\controllers;


use backend\services\ErrorLogRecordService;
use backend\services\ErrorService;
use Yii;
use yii\web\NotFoundHttpException;

class ErrorLogController extends AdminBaseController
{
    /**
     * action 之前就要执行的代码
     * @param \yii\base\Action $action
     * @return bool
     * @throws \yii\web\BadRequestHttpException
     */
    public function beforeAction($action)
    {
        $this->service = new ErrorService();
        $this->service->searchField = 'message';
        return parent::beforeAction($action); // TODO: Change the autogenerated stub
    }

    /**
     * 错误日志信息
     */
    public function actionShow()
    {
        $viewVar = [];
        //  错误日志信息
        $id = Yii::$app->request->get('id');
        $info = $this->service->getInfoByPk($id);
        if(!$info){
            throw new NotFoundHttpException('当前信息不存在');
        }
        $viewVar['info'] = $info;

        // 访问信息
        $service = new ErrorLogRecordService();
        list($recordList,) = $service->getList(['error_id'=>$id], 'create_time desc', 0, 20);
        $viewVar['recordList'] = $recordList;


        return $this->render('show', $viewVar);
    }
}